<!--执行历史参数-合约-->
<template>
  <scroller class="scroller">
      <div class="wrapper" v-if="reserves">
        
        <!--高级设置-->
        <VParam class="senior" ref="VParam" v-model="senior" :isModify="false" :isEdit="false" :isRestore="false" :reserves="reserves" :investCoin="pairMap.investCoin" :pairMap="pairMap"></VParam>
        
        <!--仓位风控-->
        <VCRisk class="control" ref="risk" v-model="isShow" :openThreshold="risk" :isEdit="true"></VCRisk>
        
          <!--其他设置-->
        <VCSet class="set" ref="upSet" v-model="other" :stopProfit="stopProfit" :stopLoss="stopLoss" :stopProfitTipe ="stopProfitTipe" :isEdit="true"></VCSet>
        <div class="height80"></div>
      </div>
    </scroller>
</template>

<script>

//组件
import VParam from "@/up/view/VParam.vue";
import VCRisk from "@/upContract/view/VCRisk.vue";
import VCSet from "@/upContract/view/VCSet.vue";

//功能
import navigator from "@/_js/navigator"; 
import modal from "@/_js/modal";
import math from "@/_js/math";

const weexFunction = weex.requireModule("WeexFunction");

import I18N from "@/_i18n/i18n";
var T = I18N.t;
weexFunction.setTitle(T('参数'));

export default {

  components: {
    VParam,
    VCRisk,
    VCSet,
  },

  data() {
    return {
      T:T,
      math:math,

      configMap:undefined, //执行配置
      isOpenFollow:false, //turn 开放跟单
      followMimic:false, //turn 模拟盘开放跟单
      
      /************************************ 参数设置*/
      reserves:undefined, //参数数组
      pairMap:undefined, //交易对

      /************************************ 其他设置*/
      stopProfit:'', //止盈
      stopLoss:'', //止损
      stopProfitTipe:'', //终止时间
      cancelOrder:true, //撤单
      isConvert:true, //兑换

      /************************************ 切换选中*/
      senior: true, //true 显示参数设置
      other: true, //true 显示其他设置
      isShow: true,
      
    };
  },

  mounted() {
    this.configMap = navigator.getParam('configMap');
    this.isOpenFollow = navigator.getParam('isOpenFollow');
    this.followMimic = navigator.getParam('followMimic');
    /************************************ 参数设置*/
    this.reserves = this.initData(this.configMap.reserves);
    // for (let index = 0; index < this.reserves.length; index++) {
    //   var reserve = this.reserves[index];
    //   delete reserve.comment;
    // }
    this.pairMap = this.configMap.tradePairs[0];
    /************************************ 其他设置*/
    this.stopProfit = this.configMap.stopProfit.length ? math.cheng(this.configMap.stopProfit, '100') : '';
    this.stopLoss = this.configMap.stopLoss.length ? math.cheng(this.configMap.stopLoss, '-100') : '';
    this.stopProfitTipe = this.configMap.stopProfitTipe;
    this.cancelOrder = this.configMap.cancelOrder;
    this.isConvert = this.configMap.isConvert;
    this.showFollow = pairMap.apiId != '';
  },

  methods: {
    
    //2021.8.5  处理老策略缺少网格分布开关参数显示异常问题。
    initData(reserves){

      for (let index = 0; index < reserves.length; index++) {
        var param = reserves[index];
        if (param.name == '网格分布') {
          break;
        }

        if (param.name == '网格间隔(等比)') {
          var value = Number(param.value) > 0 ? 0 : 1;
          var map = {'name':'网格分布', 'value':value};
          reserves.splice(index, 0, map);
          break;
        }
      }
      return reserves;
    },

  }
}
</script>


<style src="@/_css/style.css"></style>
<style scoped>
.scroller {
  width: 750px;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 9;
}
.wrapper {
  width: 750px;
}
.line{
  width: 710px;
  height: 1px;
  margin-top: 40px;
  margin-bottom: 40px;
}


.senior{
  width: 670px;
  margin-left: 40px;
  margin-top: 60px;
}

.set{
  margin-top: 40px;
  margin-left: 40px;
}

.control {
  margin-top: 40px;
  margin-left: 40px;
}


.follow{
  width: 670px;
  margin-left: 40px;
  margin-top: 40px;
}

.height80{
  height: 80px;
}
</style>